package cn.lyq.card.ui.statistics

import android.content.res.Resources
import cn.lyq.card.R
import cn.lyq.card.data.model.PosStatisticsInfo
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.razerdp.widget.animatedpieview.AnimatedPieView
import com.razerdp.widget.animatedpieview.AnimatedPieViewConfig


class DeviceStatisticAdapter(val resources: Resources) :
    BaseQuickAdapter<PosStatisticsInfo, BaseViewHolder>(
        R.layout.item_device_statistics, mutableListOf()
    ) {

    private val stroke = resources.getDimensionPixelOffset(R.dimen.margin15)
    private val radius = resources.getDimensionPixelOffset(R.dimen.dp_radius).toFloat()
    private val testSize = resources.getDimensionPixelOffset(R.dimen.font14).toFloat()

    override fun convert(holder: BaseViewHolder, item: PosStatisticsInfo) {
        holder.setText(R.id.tvDeviceType, item.title ?: "")
        holder.setText(R.id.tvNum, item.posNumber.toString())
        holder.setText(R.id.tvAct, "已激活台数：${item.posActNumber}  （${item.getActPercent()}）")
        holder.setText(R.id.tvUnAct, "未激活台数：${item.posNotActNumber}  （${item.getNotActPercent()}）")
        val pie = holder.getView<AnimatedPieView>(R.id.pie)
        pie.start(AnimatedPieViewConfig().apply {
            animatePie(false)
            startAngle(-90f)
            strokeWidth(stroke)
            drawText(false)
            canTouch(false)
            textSize(testSize)
            pieRadius(radius)
            item.getPie().forEach {
                addData(it, true)
            }
        })

    }
}